/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * 
 * Project Name:itsm-gateway
 * Create Time: 2016年1月30日 下午3:02:56
 */
package com.lenovo.lmrp.server.itsmgateway.adapter.ms;

import javax.annotation.Resource;
import javax.xml.ws.WebServiceContext;

import com.lenovo.sdc.framework.util.JSONHelper;

@javax.jws.WebService(
                      serviceName = "LenovoAppWsProcessRunServiceImplService",
                      portName = "LenovoAppWsProcessRunServiceImplPort",
                      targetNamespace = "http://webservice.itsm.lenovoapp.cust/")
                      
public class LenovoAppWsProcessRunServiceImpl implements LenovoAppWsProcessRunService {

    private static final String OK = "OK";

    private IRemedySyncHandler handler;
    
    @Resource
    private WebServiceContext wsContext;
    
    public LenovoAppWsProcessRunServiceImpl(IRemedySyncHandler handler) {
        this.handler = handler;
    }

    public String groupPeopleInfo(String xmlData) throws Exception {
        try {
            handler.processData(IRemedySyncHandler.QNAME_GROUPPEOPLE, xmlData, wsContext);
            return new SyncResponse(true, OK).toString();
        }
        catch (java.lang.Exception exp) {
            return new SyncResponse(false, exp.getMessage()).toString();
        }
    }

    public String groupInfo(String xmlData) throws Exception {
        try {
            handler.processData(IRemedySyncHandler.QNAME_GROUP, xmlData, wsContext);
            return new SyncResponse(true, OK).toString();
        }
        catch (java.lang.Exception exp) {
            return new SyncResponse(false, exp.getMessage()).toString();
        }
    }

    public String balanceInfo(String xmlData) throws Exception {
        try {
            handler.processData(IRemedySyncHandler.QNAME_BALANCE, xmlData, wsContext);
            return new SyncResponse(true, OK).toString();
        }
        catch (java.lang.Exception exp) {
            return new SyncResponse(false, exp.getMessage()).toString();
        }
    }

    public String ticketInfo(String xmlData) throws Exception {
        try {
            handler.processData(IRemedySyncHandler.QNAME_TICKET, xmlData, wsContext);
            return new SyncResponse(true, OK).toString();
        }
        catch (java.lang.Exception exp) {
            return new SyncResponse(false, exp.getMessage()).toString();
        }
    }

    public String supplierInfo(String xmlData) throws Exception {
        try {
            handler.processData(IRemedySyncHandler.QNAME_SUPPLIER, xmlData, wsContext);
            return new SyncResponse(true, OK).toString();
        }
        catch (java.lang.Exception exp) {
            return new SyncResponse(false, exp.getMessage()).toString();
        }
    }

    public String engineerInfo(String xmlData) throws Exception {
        try {
            handler.processData(IRemedySyncHandler.QNAME_ENGINEER, xmlData, wsContext);
            return new SyncResponse(true, OK).toString();
        }
        catch (java.lang.Exception exp) {
            return new SyncResponse(false, exp.getMessage()).toString();
        }
    }

    public String sayHello(String fullName) {
        return "{result:true,message:\"" + fullName + "\"}";
    }

    public String attachmentInfo(String xmlData) throws Exception {
        try {
            handler.processData(IRemedySyncHandler.QNAME_ATTACHMENT, xmlData, wsContext);
            return new SyncResponse(true, OK).toString();
        }
        catch (java.lang.Exception exp) {
            return new SyncResponse(false, exp.getMessage()).toString();
        }
    }

    public String projectInfo(String xmlData) throws Exception {
        try {
            handler.processData(IRemedySyncHandler.QNAME_PROJECT, xmlData, wsContext);
            return new SyncResponse(true, OK).toString();
        }
        catch (java.lang.Exception exp) {
            return new SyncResponse(false, exp.getMessage()).toString();
        }
    }

    public String peopleInfo(String xmlData) throws Exception {
        try {
            handler.processData(IRemedySyncHandler.QNAME_PEOPLE, xmlData, wsContext);
            return new SyncResponse(true, OK).toString();
        }
        catch (java.lang.Exception exp) {
            return new SyncResponse(false, exp.getMessage()).toString();
        }
    }

    private class SyncResponse {
        private boolean result;
        private String message;

        SyncResponse(boolean result, String message) {
            this.result = result;
            this.message = message;
        }

        public boolean isResult() {
            return result;
        }

        public String getMessage() {
            return message;
        }

        public String toString() {
            try {
                return JSONHelper.toJSON(this);
            }
            catch (Exception exp) {
                return "{result:" + result + ",message:\"" + message + "\"}";
            }
        }
    }
}
